<html>
<title><?=$title?></title>
	<head>
		<style type="text/css">
			p.serif{font-family:"Times New Roman",Times,serif;}
			p.sansserif{font-family:Arial,Helvetica,sans-serif;}
		</style>
	</head>
        <? $this->load->model('keuangan/akun_model'); ?>
	
	<body>
		<table border="0">
			<tr>
				<td>				
					<img  src="<?=base_url();?>style/images/logo-ecamp.png" width="145" height="75" />
				</td>
				<td>
					<p><h2>Laporan Laba/Rugi </h2>
                                        <br> <h3>Periode <?=$tanggal_awal.' s/d '.$tanggal_akhir?></h3>
				<td>
			</tr>
		</table>
            
		<table border="1">
		<tr style="font-weight: bold">
			<td>Keterangan</td>
			<td width="100">Saldo</td>
                        <td width="100"></td>
		</tr>
                <? $jml_pendapatan = 0; foreach ($pendapatan->result() as $revenue){?>
                <tr>
                    <td colspan="2"><?=$revenue->NAMA_AKUN?></td>
                    <td align="right"><?=$revenue->TOTAL_TRANSAKSI?></td>
                </tr>
                <? //$jml_pendapatan = 0;//$revenue->TOTAL_TRANSAKSI;
                    foreach ($child_pendapatan->result() as $cpendapatan){
                        $total = $this->transaksi_akun_model->get_total_transaksi_byAkun($cpendapatan->ID_AKUN, 1, $tanggal_awal, $tanggal_akhir);
                        $nilai_pendapatan = $total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0;
                        $jml_pendapatan += $nilai_pendapatan;
                    $next_child = $this->transaksi_akun_model->get_transaksi_byAkunParent($cpendapatan->ID_AKUN);
                ?>
                <tr>
                    <td width="250">
                        <?=$cpendapatan->NAMA_AKUN?>
                        <? //$jml_pendapatan += $cpendapatan->TOTAL_TRANSAKSI;
                        if ($next_child->num_rows() >0 ){ ?>
                        <table>
                            <? foreach ($next_child->result() as $row){
                                $total = $this->transaksi_akun_model->get_total_transaksi_byAkun($row->ID_AKUN, 1, $tanggal_awal, $tanggal_akhir);
                        $jml_pendapatan += $total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0;
                                ?>
                            <tr>
                                <td width="250"><?=$row->NAMA_AKUN?></td>
                                <td align="right"><?=$total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0?></td>
                                <td></td>
                            </tr>
                            <?}?>
                        </table>
                        <?}?>
                    </td>
                    <td align="right"><?=number_format($nilai_pendapatan, 2)?></td>
                    <td></td>
                </tr>
                <?}?>
                <tr>
                    <td colspan="2">Jumlah Pendapatan</td>
                    <td align="right"><?=number_format($jml_pendapatan, 2)?></td>
                </tr>
                <tr style="font-weight: bold">
                    <td colspan="2">LABA KOTOR</td>
                    <td align="right"><?=number_format($jml_pendapatan, 2)?></td>
                </tr>
                <?}?>

                <tr><td colspan="3">&nbsp;</td></tr>
                
                <? $jml_beban = 0; foreach ($beban->result() as $beban){?>
                <tr>
                    <td colspan="2"><?=$beban->NAMA_AKUN?></td>
                    <td align="right"><?=$beban->TOTAL_TRANSAKSI?></td>
                </tr>
                <? $jml_beban = $beban->TOTAL_TRANSAKSI; foreach ($child_beban->result() as $cbeban){
                    $total = $this->transaksi_akun_model->get_total_transaksi_byAkun($cbeban->ID_AKUN, 0, $tanggal_awal, $tanggal_akhir);
                        $nilai_beban = $total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0;
                        $jml_beban += $nilai_beban;
                    $next_child = $this->transaksi_akun_model->get_transaksi_byAkunParent($cbeban->ID_AKUN);
                ?>
                <tr>
                    <td width="250">
                        <?=$cbeban->NAMA_AKUN?>
                        <? //$jml_beban += $cbeban->TOTAL_TRANSAKSI;
                        if ($next_child->num_rows() >0 ){ ?>
                        <table>
                            <? foreach ($next_child->result() as $row){
                                $total = $this->transaksi_akun_model->get_total_transaksi_byAkun($row->ID_AKUN, 0, $tanggal_awal, $tanggal_akhir);
                        $jml_beban += $total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0;
                                ?>
                            <tr>
                                <td width="250"><?=$row->NAMA_AKUN?></td>
                                <td align="right"><?=$total->num_rows() > 0 ? $total->row()->TOTAL_TRANSAKSI:0?></td>
                                <td></td>
                            </tr>
                            <?}?>
                        </table>
                        <?}?>
                    </td>
                    <td align="right"><?=number_format($nilai_beban, 2)?></td>
                    <td></td>
                </tr>
                <?}?>
                <tr>
                    <td colspan="2">Jumlah Beban</td>
                    <td align="right"><?=number_format($jml_beban, 2)?></td>
                </tr>
                <?}?>
                <tr style="font-weight: bold">
                    <td colspan="2">
                        <? if ($jml_pendapatan >= $jml_beban) echo 'LABA BERSIH'; else echo 'RUGI BERSIH';?>
                    </td>
                    <td align="right"><?=number_format($jml_pendapatan-$jml_beban, 2)?></td>
                </tr>
		</table>
	</body>
</html>